package LB2;

import static java.lang.Math.sin;
import static java.lang.Math.pow;
/**
 * Created with IntelliJ IDEA.
 * User: Борис
 * Date: 14.10.13
 * Time: 19:54
 * To change this template use File | Settings | File Templates.
 */
public class FirstRang extends AbstractCalculateDiff{

    public FirstRang(double[] interval, double h){
        super(interval,h);
    }
    public double[][] firstDiff(){
        double[][] result = new double[2][size];
        for(int i = 0; i<size; i++){
            result[0][i] = interval[i];
            if (i!=size-1)
                result[1][i] = (sin(interval[i+1])-sin(interval[i]))/h;
            else result[1][i] = (sin(interval[i])-sin(interval[i-1]))/h;
        }
        return result;
    }
    public double[][] secondDiff(){
        double[][] result = new double[2][size];
        for(int i = 0; i<size; i++){
            result[0][i] = interval[i];
            if (i<2)
                result[1][i] = (sin(interval[i+2]) - 2*sin(interval[i+1]) + sin(interval[i]))/pow(h,2);
            else result[1][i] = (sin(interval[i-2]) - 2*sin(interval[i-1]) + sin(interval[i]))/pow(h,2);
        }
        return result;
    }
}
